package com.simon.hse.activity.safe.jobticket.earth;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.simon.hse.MyApplication;
import com.simon.hse.R;
import com.simon.hse.activity.BaseActivity;
import com.simon.hse.activity.safe.jobticket.fire.FireApplyActivity;
import com.simon.hse.adapter.CommonAdapter;
import com.simon.hse.adapter.CommonViewHolder;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * 动土作业许可证申请
 */
@SuppressWarnings("all")
@ContentView(R.layout.activity_apply_earth)
public class EarthApplyActivity extends BaseActivity {
    @ViewInject(R.id.tv_common_title)
    TextView mTv_common_title;
    @ViewInject(R.id.recyclerview_aqcs)
    RecyclerView recyclerview_aqcs;

    @ViewInject(R.id.ll_applicant_unit)
    LinearLayout ll_applicant_unit;
    @ViewInject(R.id.tv_applicant_unit)
    TextView tv_applicant_unit;

    @ViewInject(R.id.ll_workunit)
    LinearLayout ll_workunit;
    @ViewInject(R.id.tv_workunit)
    TextView tv_workunit;

    @ViewInject(R.id.ll_workplace)
    LinearLayout ll_workplace;
    @ViewInject(R.id.tv_workplace)
    TextView tv_workplace;

    @ViewInject(R.id.ll_start_time)
    LinearLayout ll_start_time;
    @ViewInject(R.id.tv_start_time)
    TextView tv_start_time;

    @ViewInject(R.id.ll_end_time)
    LinearLayout ll_end_time;
    @ViewInject(R.id.tv_end_time)
    TextView tv_end_time;
    private CommonAdapter commonAdapter;
    private List<String> mDataBeanList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mTv_common_title.setText("动土作业许可证申请");
        initRecyclerView();
        initData();
    }

    @Event(value = {R.id.iv_common_left, R.id.iv_common_right, R.id.iv_add_aqcs, R.id.iv_delete_aqcs
            ,R.id.ll_applicant_unit, R.id.ll_workunit, R.id.ll_workplace, R.id.ll_start_time, R.id.ll_end_time})
    private void back(View view) {
        switch (view.getId()) {
            case R.id.iv_common_left:
                finish();
                break;
            case R.id.iv_add_aqcs:
                mDataBeanList.add("");
                commonAdapter.notifyDataSetChanged();
                break;
            case R.id.iv_delete_aqcs:
                mDataBeanList.remove(mDataBeanList.size() - 1);
                commonAdapter.notifyDataSetChanged();
                break;
            case R.id.ll_applicant_unit:
                initSafePop(ll_applicant_unit, tv_applicant_unit, MyApplication.getInstance().mSafeNullList);
                break;
            case R.id.ll_workunit:
                initSafePop(ll_workunit, tv_workunit, MyApplication.getInstance().mSafeNullList);
                break;
            case R.id.ll_workplace:
                initSafePop(ll_workplace, tv_workplace, MyApplication.getInstance().mSafeNullList);
                break;
            case R.id.ll_start_time:
                publishSafeDate(tv_start_time);
                break;
            case R.id.ll_end_time:
                publishSafeDate(tv_end_time);
                break;
        }
    }

    private void initRecyclerView() {
        LinearLayoutManager llm = new LinearLayoutManager(EarthApplyActivity.this);
        recyclerview_aqcs.setLayoutManager(llm);
        // 如果Item够简单，高度是确定的，打开FixSize将提高性能
        recyclerview_aqcs.setHasFixedSize(true);
        // 设置Item默认动画，加也行，不加也行
        recyclerview_aqcs.setItemAnimator(new DefaultItemAnimator());
        recyclerview_aqcs.setNestedScrollingEnabled(false);
        commonAdapter = new CommonAdapter(EarthApplyActivity.this, R.layout.item_fire_aqcs, mDataBeanList);
        commonAdapter.setItemDatasListener(new CommonAdapter.ItemDatasListener<String>() {
            @Override
            public void setItemDatas(CommonViewHolder holder, String dataBean, int position) {
            }
        });
        recyclerview_aqcs.setAdapter(commonAdapter);
    }

    private void initData() {
        mDataBeanList.add("");
        commonAdapter.notifyDataSetChanged();
    }
}
